/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


package com.Cloudtap.Backend;
import java.util.*;


public abstract class BaseVM implements iVM {

    protected HashMap<UUID, Object> vmProperties;

    public BaseVM(String name, String description, Date creationTime,
            VMState state, String OS)
    {
        this.vmProperties = new HashMap<UUID,Object>();
        this.SetProperty(BaseVMTypePropertyID.Name,name);
        this.SetProperty(BaseVMTypePropertyID.Description, description);
        this.SetProperty(BaseVMTypePropertyID.CreationTime, creationTime);
        this.SetProperty(BaseVMTypePropertyID.State, state);
        this.SetProperty(BaseVMTypePropertyID.OperatingSystem, OS);
        
    }

    @Override
    public Object GetProperty(UUID propertyID) {
        return this.vmProperties.get(propertyID);
    }


    @Override
    public void SetProperty(UUID propertyID, Object value)
    {
        this.vmProperties.put(propertyID, value);
    }

    @Override public boolean equals(Object obj) {
        if ( this == obj )
        {
            return true;
        }

        if ( !(obj instanceof iVM) )
        {
            return false;
        }

        iVM otherVM = (iVM)obj;

        //Check if all the properties are the same
        if (this.GetVMType().GetSupportedProperties().size() != otherVM.GetVMType().GetSupportedProperties().size())
        {
            return false;
        }
    
        for (UUID propertyID : vmProperties.keySet())
        {
            Object value1 = otherVM.GetProperty(propertyID);
            Object value2 = this.GetProperty(propertyID);
                if (!value1.equals(value2))
                {
                    return false;
                }
        }

        //TODO Consider operations for equals implementation?
        
        return true;
    }

    @Override public int hashCode() {
        return 0;
    }
}
